package com.auxgroup.hr.front.service.modperson.impl;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.auxgroup.hr.front.service.hireperson.impl.HireEducatServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import com.auxgroup.hr.front.commons.utils.ObjectFieldUtils;
import com.auxgroup.hr.front.commons.vo.UserDTO;
import com.auxgroup.hr.front.dao.domain.PsCModSocial;
import com.auxgroup.hr.front.dao.domain.PsCModSocialPrimary;
import com.auxgroup.hr.front.dao.repository.PsCModSocialRepository;
import com.auxgroup.hr.front.service.modperson.ModSocialService;

/** 
 * @author lvliuhao
 * @version 创建时间：180526 
 * 公积金流程信息service
 */
@Service("modSocialService")
public class ModSocialServiceImpl implements ModSocialService {
	private static final Logger logger = LoggerFactory.getLogger(HireEducatServiceImpl.class);
	
	@Autowired
	private PsCModSocialRepository PsCModSocialRepository;


	@Override
	public PsCModSocial getModSocial(PsCModSocialPrimary primary) {
		return PsCModSocialRepository.findOne(primary);
	}


	@Override
	public PsCModSocial save(PsCModSocial ModSocial,UserDTO user) {
		ModSocial.setHrsRowAddOprid(user.getOprId());
		ModSocial.setHrsRowAddDttm(new Timestamp(System.currentTimeMillis()));
		ModSocial.setHrsRowUpdOprid(user.getOprId());
		ModSocial.setHrsRowUpdDttm(new Timestamp(System.currentTimeMillis()));
		Set<String> ignoreFields = new HashSet<String>(Arrays.asList("cSeqno"));
		ObjectFieldUtils.handleNullValue(ModSocial,ignoreFields);
		return PsCModSocialRepository.save(ModSocial);
	}


	@Override
	public Boolean delete(PsCModSocialPrimary primary) {
		try {
			PsCModSocialRepository.delete(primary);
		} catch (Exception e) {
			logger.error("delete ModSocial error: modPerPrimary={}",primary,e);
			return false;
		}
		return true;
	}
	
	
	@Override
	public List<PsCModSocial> getAll(String emplId) {
		PsCModSocial ModSocial = new PsCModSocial();
		ModSocial.setEmplid(emplId);
		return PsCModSocialRepository.findAll(Example.of(ModSocial));
	}


	/* (non-Javadoc)
	 * @see ModSocialService#getAll(java.lang.String, java.lang.String)
	 */
	@Override
	public List<PsCModSocial> getAll(String cTransactionNbr, String emplId) {
		PsCModSocial ModSocial = new PsCModSocial();
		ModSocial.setEmplid(emplId);
		ModSocial.setcTransactionNbr(cTransactionNbr);
		return PsCModSocialRepository.findAll(Example.of(ModSocial));
	}


	
	
	
}
